/*
 JavaScript lib.js by martin $ 2010/05/26 12:21:43
*/
var d = document, DE = d.documentElement, UD = 'undefined';

var client = oParts.client;
var toolTip, ed, loadingImg, loadingAni, loaderAni, expandImg, unexpandImg, screenBack, closeButton;
var ImagePath = 'Images/';
var baseURL = oParts.baseURL;
var ONAME, ADMIN, AUTO_LOGIN, SOLO, OADMIN, UNAME;

oParts.loadScript(baseURL + 'js/syntax.js');

function googleIt(query){
 window.open(encodeURI("http://www.google.com/search?hl=ja&ie=UTF-8&oe=UTF-8&q="+query));
}
function wikipediaIt(query){
 window.open("http://ja.wikipedia.org/wiki/%E7%89%B9%E5%88%A5:Search?search="+encodeURIComponent(query));
}

function my_confirm(text){
 text += "削除しますか？";
 if(!confirm(text)) return false; else return true;
}

function readMore(self){
 var s, ob; self = o(self); ob = self.sib(1);
 if(!ob.visible()){
  self.title('記事をたたむ').html('&laquo;やっぱり隠す').css('background-position:0 100%'); s = ob.html();
  if(/corner\-play/.test(s)) cornerPlay(ob.$);
  if(/photo\-effect/.test(s)){
   if(typeof photoEffect != UD) photoEffect.init(ob.$);
  }
  ob.show();
 } else {
  self.title('続きをよむ').html('&raquo;続きを読む').css('background-position:0 0');
  ob.hide();
 }
}

function toggleBox(self, target){
 if(!target) return;
 target.toggle(); var tv = target.visible();
 self.css('background-position:' + ['0 100%', '0 0'][tv]);
 self.title(['展 開！', '閉じます'][tv]);
 oParts.cookie.set('PPBLOG_SIDEBAR_'+self.parent(2).id.toUpperCase()+'_STATE', ['+', '-'][tv]);
}

var Caret = { // マウスで指定したポイントあるいは文字列に要素を挿入
 getArea : function(){
  if(typeof ed == UD){
   if(o('#Page1')) ed = o('#Page1');
   else if(o('#c_com')) ed = o('#c_com');
   else ed = o('textarea').item(0);
  }
  return ed || ed.$;
 },
 selection : '',
 get : function(){
  var area = Caret.getArea();
  if(client.MSIE){
   if(!document.selection.createRange()) area.focus();
   Caret.range =  document.selection.createRange().duplicate();
   return Caret.selection = Caret.range.text;
  } else {
   return Caret.selection = area.value.substring(area.selectionStart, area.selectionEnd);
  }
 },
 set : function(string){
  var area = Caret.getArea();
  if(client.MSIE){
   if(Caret.selection.length > 0){
    Caret.range.text = string;
    Caret.range.select();
   } else {
    area.focus();
    Caret.range = document.selection.createRange().duplicate();
    Caret.range.text = string;
   }
  } else {
   if(Caret.selection.length >= 0 && area.selectionStart >= 0){
    var s = area.selectionStart, scrollTop = area.scrollTop;
    area.value = area.value.slice(0, s) + area.value.slice(s).replace(Caret.selection, string);
    area.setSelectionRange(eval(s + string.length), eval(s + string.length));
    area.scrollTop = scrollTop; // Firefoxでカーソルがトップに戻らないための処理
    area.focus();
   } else area.value += string;
  }
 }
}
function loadComments(uid){
 var commentsDiv = o('#responses-' + uid);
 var tar = oParts.target(), ownerDiv = o('#UID' + uid), diff;
 var cform = o('#comment' + uid), tbform = o('#trackbacks-' + uid);
 if(tar.$.disabled) return;
 if(o('#responses')){ o('#responses').view(2); return;}
 
 if(commentsDiv){ // already loaded and displayed
  if(commentsDiv.visible()){
   o([commentsDiv, cform, tbform]).hide();
   tar.html(tar.html().replace(/\[\-\]/, '[+]')).css('white-space: nowrap').title('コメントを表示します');
  } else {
   o([commentsDiv, cform]).show();
   tar.html(tar.html().replace(/\[\+\]/, '[-]')).css('white-space: nowrap').title('表示したコメントを隠します');
   if((diff = commentsDiv.$.offsetTop - oParts.metrics(3)) > 0){ // out of screen
    oParts.scroll(diff);
   }
  }
 } else {
  tar.$.disabled = true;
  ajaxTooltip('コメント'); if(tbform) tbform.away();
  oParts.server.get(baseURL + 'ajax.php?type=comments&aim='+uid, function(data){
   commentsDiv = oParts.fragment(data);
   ownerDiv.addAfter(commentsDiv); commentsDiv = o('#responses-' + uid);
   tar.html(tar.html().replace(/\[\+\]/, '[-]')).title('表示したコメントを隠します');
   toolTip.html(' コメント読み込み完了！ ');
   tar.$.disabled = false;
   if((diff = commentsDiv.$.offsetTop - oParts.metrics(3)) > 0){ // out of screen
    oParts.scroll(diff);
   }
  });
 }
}

function loadCommentForm(uid, entree){ /* revised in v1.8.0 */
 var cform = o('#comment' + uid), tbform = o('#trackbacks-' + uid), cformIn = o('#comment');
 if(!cform) ajaxTooltip('コメントフォーム');
 if(typeof ONAME == UD) oParts.loadScript(baseURL + 'ajax.php?type=info');
 oParts.loadScript(baseURL + 'ajax.php?type=json');
 oParts.loadScript(baseURL + 'js/comment.js');
 var ownerDiv = o('#UID' + uid);
 var tar = oParts.target(), div, intro, diff;
 var closec = 'コメントフォームを閉じます', tocf = 'コメントフォームへ';
 var open = ' コメントする ', close = '　閉じる　';
 var commentsDiv = o('#responses-' + uid);
 if(!cform){
  if(ONAME){
   tar.$.disabled = true;
   if(cformIn){ var p = cformIn.parent(1); cformIn.away(); p.away();}
   oParts.server.get(baseURL + 'ajax.php?type=commentform&UID=' + uid, function(data){
    cform = oParts.fragment(data);
    if(commentsDiv){
     commentsDiv.addAfter(cform); cform = o('#comment' + uid);
    } else {
     ownerDiv.addAfter(cform); cform = o('#comment' + uid);
    }
    if(!entree) tar.html(close).title(closec);
    if(tbform) tbform.away();
    toolTip.hide();
    tar.$.disabled = false;
    if((diff = cform.$.offsetTop - oParts.metrics(3)) > 0) oParts.scroll(diff);
   }, false);
  }
 } else {
  if(entree){
   cform.view(2);
  } else {
   tar.title() != closec ? cform.show() : cform.hide();
   if((diff = cform.$.offsetTop - oParts.metrics(3)) > 0) oParts.scroll(diff);
   tar.html(cform.visible() ? close : open).css('white-space: nowrap;').title(cform.visible() ? closec : tocf);
  }
 }
}

function loadTrackBacks(uid, entree){ /* revised in v1.8.0 */
 var tbform = o('#trackbacks-' + uid), cform = o('#comment' + uid), ownerDiv = o('#UID' + uid);
 var commentsDiv = o('#responses-' + uid), tar = oParts.target();
 if(!tbform){
  ajaxTooltip('TrackBackフォーム');
  tbform = oParts.create('div#trackbacks-'+uid, null, null, true);
  oParts.server.get(baseURL + 'ajax.php?type=trackback&UID='+uid, function(data){
   tbform.html(data);
   ownerDiv.addAfter(tbform);
   if(cform){
    o('p.comment-intro', cform).item(0).away();
    o('p.trackback-alert', cform).away();
   }
  });
 } else {
  tbform.toggle();
 }
}

function ajaxTooltip(prefix){ /* from v1.7.0 */
 var x, y, w, s, a = arguments, e = oParts.evt, cW = oParts.metrics(0), cH = oParts.metrics(1), scY = oParts.metrics(3);
 if(e && !a[2]){
  x = e.pageX + (cW/2 < e.pageX ? -200 : 90);
  y = e.pageY - 30; s = loaderAni;
 } else {
  x = (cW - 150) / 2 + 100; w = 150; s = a[2];
  y = (client.MSIE6 ? scY : 0)+ parseInt((cH - 24) * .35);
 }
 if(typeof toolTip == UD){
  toolTip = oParts.create('div#ajaxToolTip', 'background:ivory; border:1px solid #333; padding:3px 5px; text-align: center; font-size:12px; z-index:10000;');
  toolTip.dimension(x, y - 10, 180, 24).on('click', function(){toolTip.hide();});
 } else {
  toolTip.css('opacity:1;'+pos).moveTo(x, y - 10).show();
 }
 var txt = '  ' + prefix + (a[1] || '読み込み中...');
 var pos = (!a[2] || client.MSIE6) ? 'position: absolute;' : 'position: fixed;';
 toolTip.css(pos).html('<img src="'+s+'" alt="loading..." style="vertical-align:middle;"/> ' + txt).sizeTo(txt.length * 12, 18);
}

function loadPage(uid, page, headline){
 ajaxTooltip(headline ? 'この続きを' : '次のページを');
 uid = uid.replace(/d$/,'');
 oParts.server.get(baseURL + "ajax.php?type=page&UID="+uid+"&page="+page, function(data){
  var ownerDiv = o("#UID" + uid);
  var articleContent = o(".article-content", ownerDiv), commentsButton = o(".cute-button", ownerDiv);
  var response = o('#responses-'+uid);
  if(data.indexOf("\t\t") > 0){
   var mod = data.split(/\t\t/)[0]; data = data.split(/\t\t/)[1];
   applyScript(mod);
  }
  articleContent.css('line-height: 1.7;');
  if(!headline) ownerDiv.view(1);
  if(response && response.visible()){
   if(commentsButton){
    var commentsButton_text = commentsButton.html();
    commentsButton.away();
   }
  }
  articleContent.html(data);
  cornerPlay(articleContent);
  var commentsButton = o(".cute-button", ownerDiv);
  if(commentsButton){
   commentsButton.html(commentsButton_text);
  }
  if(!headline && commentsButton) articleContent.addChild(commentsButton);
  if(typeof photoEffect != UD) photoEffect.init(ownerDiv.$);
  if(typeof pettieSyntax != UD) pettieSyntax();
  if(client.Safari) self.pageYOffset = ownerDiv.offsetTop;
  var editLink = o('a[rel=edit]', ownerDiv);
  if(editLink){
   editLink.each(function(a){a.href = (a.href.replace(/&?page=\d+$/, '') + "&page=" + page);});
  }
 });
}

function loadArticle(uid){
 uid = uid.replace(/d$/,'');
 ajaxTooltip('記事を');
 articleViewer = o('#article-viewer'), offsetY = 160;
 var viewerWidth = parseInt(oParts.metrics(0)-120);
 var cW = oParts.metrics(0), cH = oParts.metrics(1), dH = oParts.metrics(2), scY = oParts.metrics(3);
 if(!articleViewer){
  var Screen = oParts.create('div', 'z-index:999').dimension(0, 0, cW, dH).css('background:url('+screenBack+')');
  if(client.IE6) Screen.css('opacity:.73');
  articleViewer = oParts.create('div#article-viewer', 'z-index:5000; display:none;').dimension(60, offsetY, viewerWidth, null);
  var _bt = oParts.create('div', 'background:url(Images/cssbox.png) no-repeat 100% 0; margin:0 0 0 17px; height:17px; padding:0;', articleViewer);
  oParts.create('div', 'margin:0;background:url(Images/cssbox.png) no-repeat 0 0;', _bt).dimension(-17, 0, 17, 17, 'rel');
  var _bl = oParts.create('div', 'background:url(Images/bl.png) repeat-y 0 0; padding-left: 12px; height:100%;', articleViewer); // bor-l
  oParts.create('div', 'height:100%; background:url(Images/br.png) repeat-y 100% 0; padding:0;', _bl); // bor-r
  var _bb = oParts.create('div', 'background:url(Images/cssbox.png) no-repeat 100% 100%; height:17px; margin:0 0 0 17px;', articleViewer); // bor-b
  oParts.create('div', 'margin:0; background:url(Images/cssbox.png) no-repeat left bottom;', _bb).dimension(-17, 0, 17, 17, 'rel'); // bot-l
  articleViewerContent = oParts.create('div', 'background:#fff; height:100%; margin:0 12px 0 0; padding:1em;', _bl.child(0)); // content
  if(client.IE6) articleViewerContent.css('height: 1%;'); // for buggy IE6
  var closeImg1 = oParts.create('img.close-button', 'cursor:pointer;', articleViewer).dimension(0, 0, 75, 16);
  closeImg1.src(closeButton).title('閉じる');
  var closeImg2 = closeImg1.clone(true);
  o([closeImg1, closeImg2]).on('click', function(){
   o([articleViewer, Screen]).away();
   if(client.Gecko) o([MozToolTip, MozToolTipShadow]).hide();
  });
  articleViewer.addChild(closeImg2);
  
  articleViewerContent.on('mouseover', function(){
   setTimeout(
    function(){
     var viewerHeight = articleViewer.css('height');
     closeImg2.moveTo(parseInt(viewerWidth - 100), parseInt(viewerHeight - 35));
     if(viewerHeight > dH) Screen.sizeTo(null, viewerHeight + 200);
    }, 100);
  });
 }
 oParts.server.get(baseURL + "ajax.php?type=article&UID="+uid, function(data){
  if(o('#UID' + uid)){ articleViewer.moveTo(60, offsetY);return;}
  var closeImg1 = articleViewer.child(3), closeImg2 = articleViewer.child(4);
  var nav = data.split(/\$/)[0], content = data.split(/\$/)[1];
  if(/\t\t/.test(nav)){
   var newCSS, newJS, mod = nav.split(/\t\t/)[0];
   nav = nav.split(/\t\t/)[1];
   applyScript(mod, true);
  }
  articleViewerContent.html(nav + content + nav);
  cornerPlay(articleViewerContent);
  if(typeof photoEffect != UD) photoEffect.init(articleViewerContent.$);
  if(typeof pettieSyntax != UD) pettieSyntax();
  var scr = articleViewerContent.$.getElementsByTagName("script");
  if(scr.length){
   var queue = [];
   d.write = d.writeln = d.__write;
   d.write = d.writeln = function(s){ queue.push(s); }
   for (var i = 0, l = scr.length; i < l; i++){
    if(scr[i].src){
     var _scr = scr[i], _script = d.createElement('script');
     _script.type = "text/javascript";
     _script.src = _scr.src;
     d.body.appendChild(_script);
     if(client.MSIE){
      _script.onreadystatechange = function(){
       if(_script.readyState == "complete" || _script.readyState == "loaded"){
        _scr.parentNode.insertBefore(oParts.fragment(queue.join("")), _scr.nextSibling);
        d.write = d.writeln = d.__write;
       }
      }
     } else {
      _script.onload = function(){
       _scr.parentNode.insertBefore(oParts.fragment(queue.join("")), _scr.nextSibling);
       d.write = d.writeln = d.__write;
      }
     }
    } else {
     eval(scr[i].text || scr[i].innerHTML);
    }
   }
  }
  articleViewer.show();
  
  var viewerHeight = articleViewer.css('height');
  closeImg1.moveTo(parseInt(viewerWidth - 100), 15);
  closeImg2.moveTo(parseInt(viewerWidth - 100), parseInt(viewerHeight - 35));
  window.scrollTo(0, offsetY - 50);
 });
}

function applyScript(tar, init){ /* from v1.8.0 */
 var newJS, js = /\[script\]([\s\S]+?)\[\/script\]/g.exec(tar);
 var cssRe = /\[style\]([\s\S]+)\[\/style\]/g, newCSS, css = cssRe.exec(tar);
 if(css){
  cssRe.lastIndex = 0; // for reset
  if(typeof CSSScript == UD){
   CSSScript = oParts.create("style#cssScript", null, o("head"));
   newCSS = CSSScript.$;
   newCSS.type = "text/css";
  } else newCSS = CSSScript.$;
  /*@cc_on @*//*@if(1) newCSS.styleSheet.cssText += css[1]; @else@*/
  if(init) newCSS.textContent = "";
  newCSS.appendChild(d.createTextNode(css[1]));
  /*@end@*/
 }
 if(js){
  if(typeof JSScript == UD){
   JSScript = oParts.create("script#jsScript", null, o("head"));
   newJS = JSScript.$;
   newJS.type = "text/javascript";
   newJS.text = js[1];
  } else eval(JSScript.$.text);
 }
}

function loadMedia(ob, movf, ftype){ /* from ppBlog v1.5.5 */
 var clsid;
 if(ob.href.match(/\.3gp|x\-mpeg/)){
  clsid = client.MSIE ? 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"' :
               'type="video/3gpp" data="'+movf+'"';
 } else clsid = 'type="'+ftype+'" data="'+movf+'"';
 ob.style.display = "none";
 ob.parentNode.parentNode.innerHTML += '<div class="media-part">'
  + '<h6 title="動画へのダイレクトリンク">::<a class="media-link" href="'+movf+'">'+movf+'</a>::</h6>'
  + '<object '+clsid+' width="176" height="160">'
  + '<param name="type" value="'+ftype+'" />'
  + '<param name="src" value="'+movf+'" />'
  + '<param name="autoplay" value="true" />'
  + '</object></div>';
}

function cornerPlay(elm){
 var RS = oParts.query('.corner-play', elm);
 if(RS) oParts.server.get(baseURL + 'js/cornerplay.js', function(script){eval(script);});
}

function AjaxLogIn(){
 var id = o('#ID').$, pwd = o('#PWD').$, submit = o('#loginSubmit').$;
 submit.disabled = true;
 if(typeof MD5 == 'object'){
  var auto = (o('#auto_login') && o('#auto_login').checked()) ? 1 : 0;
  oParts.server.post(baseURL + 'admin.php', 'mode=login&ID='+MD5.$(id.value)+'&PWD='+MD5.$(pwd.value)+'&type=ajax&auto_login='+auto,
   function(to){
    if(to.match(/\.php[\?|]$/)){
     d.write('<script type="text\/javascript">window.location.href="'+to+'";<\/script>');
    } else {
     alert(to);
     submit.disabled = false;
     id.focus();
    }
   }
  );
 } else alert("md5.js module Not Loaded!");
}

function AjaxLogInForm(){
 oParts.loadScript(baseURL + 'js/md5.js'); window.scrollTo(0, 0);
 var info = oParts.loadScript(baseURL + 'ajax.php?type=info');
 var loginCS = new Image(14,14).src = baseURL + 'Images/dialog-close.png';
 var cW = oParts.metrics(0), dH = oParts.metrics(2); 
 var BS = oParts.create('div', 'background-color:#708090; z-index:999; opacity: 0.73;').dimension(0, 0, cW, dH);
 var IO = oParts.create('div', 'z-index:1000; text-align:center;').dimension(Math.round((cW-270)/2), -160, 270, 160);
 IO.css('border:outset 3px #aaa; border-top-width:0; background:#ccc url(Images/login-bg.png) repeat-x; padding:5px 20px 0 20px;');
 var UI = '<h3 style="font-weight: 800;">ppBlog*Login</h3>\n';
 var CS = oParts.create('img', 'cursor:pointer;').title(' 閉じる ').src(loginCS);
 if(info && AUTO_LOGIN){
  IO.dimension(null, 0, null, 120);
  UI += '<p style="line-height:1.3;">自動ログインが有効です.<br />ログインモードに移ります.</p>'
      + '<p><input id="auto_login" name="auto_login" type="hidden" value="1" /></p>';
 } else {
  IO.sizeTo(null, (SOLO ? 180 : 160));
  UI += '<p style="font-weight:600; line-height:1;"><label for="ID"> I D </label><input type="text" name="ID" id="ID" /><br />'
     + '<label for="PWD">PWD </label><input type="password" name="PWD" id="PWD" /></p>'
     + (SOLO ? '<p><label for="auto_login" title="次回から自動ログインモードになります">auto-login mode?</label> '
     + '<input id="auto_login" name="auto_login" type="checkbox" value="1" style="vertical-align: middle;" /><br /></p>\n' : '\n')
     + '<p><button type="submit" id="loginSubmit">&nbsp;</button></p>';
 }
 IO.html(UI); IO.addChild(CS); CS.dimension(287, 4, 14, 14);
 CS.on('click', function(){ o([BS, IO]).away();});
 if(info && AUTO_LOGIN){
  oParts.server.post(baseURL + 'admin.php', "mode=login&type=auto_login&ref="+location.search, function(to){
   if(/\.php/.test(to)){
    if(/</.test(to)) to = baseURL + 'admin.php';
    setTimeout('window.location.replace("'+to+'");', 1200);
   }
  });
 } else {
  var fieldcss = "color:#333; height:21px; vertical-align:middle; padding:2px 8px 0 9px; width:160px; border-width:0;"
              + "margin-bottom: 5px; background: transparent url(Images/txtfield-bg.png) no-repeat 0 0;"
              + 'font: 600 15px "Trebuchet MS", Tahoma, Verdana, Arial, Helvetica;';
  var btncss = "margin:9px auto 0 auto;width:64px; height:28px; border-width:0; cursor:pointer;"
             + "background: transparent url(Images/submit-button.png) no-repeat;";
  o('#loginSubmit').css(btncss).title('Check it out').on('click', AjaxLogIn);
  o('#ID').css(fieldcss).css('margin-left:10px'); o('#PWD').css(fieldcss);
  (function(ob){ob.style.top = (parseInt(ob.style.top)+10) +'px'}).loop(30, 16)(IO.$);
  (function(){o('#ID').focus()}).await(1000)();
 }
}

function imagePop(e, path, w, h){
 var cW = oParts.metrics(0), cH = oParts.metrics(1), dH = oParts.metrics(2), scY = oParts.metrics(3);
 var ev = oParts.evt.target, ratio, ow = w, oh = h, imgPop;
 if(o('#article-viewer')) articleViewer.moveTo(60, -100000);
 if(w > cW-20 || h > cH-70){
  ratio = Math.min((cW-20)/w, (cH-70)/h);
  w = Math.round(w * ratio); h = Math.round(h * ratio);
 } else ratio = 1;
 if(!imgPop){
  var imgWrap = oParts.create('div', 'background:#fff; z-index:9999; border:1px solid #aaa; padding:10px;');
  imgWrap.dimension(Math.round((cW-w)/2), Math.ceil((cH-h-70)*.4)+scY, w, h + 45);
  var imgCaption = oParts.create('p', 'text-align:right; font:500 9pt/1.5 Trebuchet MS; color:navy; display:none;', imgWrap);
  imgCaption.dimension(0, h + 20, w, null);
  imgPop = oParts.create('img', 'background:#fff; border:1px solid #aaa; display:none;', imgWrap).dimension(10, 10, w, h);
  var Screen = oParts.create('div', 'z-index:999').dimension(0, 0, cW, dH).css('background:url('+screenBack+')');
  loadingImg = oParts.create('img', 'background:#fff; z-index:999', imgWrap).moveTo(Math.round(imgWrap.W * .5), Math.round(imgWrap.H * .5));
  var closeImg = oParts.create('img', 'cursor:pointer', imgWrap).dimension(imgWrap.W-68, 15, 75, 16).src(closeButton).title('閉じる');
  if(ratio < 1){
   var expand = oParts.create('img', 'z-index:1000; cursor:pointer; display:none;', imgWrap).dimension(12, 12, 34, 34);
   expand.title(' 実物大で表示 ').src(expandImg);
   expand.active = false;
  }
  loadingImg.src(loadingAni);
  if(client.IE6) Screen.css('opacity:.73');
  var caption = (typeof ev._title == UD) ? ev.title : ev._title;
  caption = caption.replace(/[\r\n]+/g,'<br/>').replace(/\s/g,'&nbsp;');
  caption = caption.split(/<br\/?>/);
  if(caption.length > 1){
   var photocaption = o('.photo-caption', oParts.evt.target.parentNode.parentNode);
   if(photocaption) caption[0] = '<span style="float:left;padding-left:1em;color:#73596d;width:'+(w - 210)+'px;text-align:left;">' + photocaption.html() + '</span>' + caption[0];
   imgCaption.html( (caption[0]+'<br />'+caption[1]+' ('+ow+'×'+oh+')') );
  } else imgCaption.html('画像をクリックすると閉じます <img src="'+ImagePath+'info2.png" width="21" height="14" alt="info" />');
  imgPop.src(path);
  var imgReady = function(){
   o([imgPop, imgCaption]).show(); loadingImg.hide();
   if(expand) expand.show();
  }
  imgPop.$.complete ? imgReady() : imgPop.on('load', imgReady);
  o([closeImg, imgPop]).on('click', function(){
   if(o('#article-viewer')) articleViewer.moveTo(60, 160);
   if(client.Gecko) o([MozToolTip, MozToolTipShadow]).hide();
   o([imgWrap, Screen]).away();
   imgPop = null;
  });
  if(ratio < 1){
   expand.on('click', function(){
    if(!expand.active){
     var iX = Math.round((cW-w) / 2);
     imgWrap.dimension(iX + ow + 22 < cW ? iX : 0, scY, ow+3, oh); imgPop.sizeTo(ow, oh); Screen.sizeTo(null, Screen.H < oh ? oh + 20 : null);
     closeImg.moveTo(imgWrap.W - 66, null); imgCaption.hide();
     expand.title(' ウィンドウのサイズに合わせる ').src(unexpandImg); expand.active = true;
    } else {
     imgWrap.dimension(Math.round((cW-w)/2), scY, w, h+45); imgCaption.show();
     imgPop.sizeTo(w, h); closeImg.moveTo(imgWrap.W-66, null); Screen.sizeTo(null, Screen.H);
     expand.title(' 実物大で表示 ').src(expandImg); expand.active = false;
    }
   });
  } //#ratio==1
  imgPop.title('マウスクリックで閉じます').css('cursor: url('+ImagePath+'zoomout.cur), pointer');
 } //#imgPop==null
}

function initCSSHover(){
 if(client.MSIE){
  if(o('#theme-selector')){
   var root = o('#theme-selector');
   root.on('mouseover', function(){this.className+=' over';});
   root.on('mouseout', function(){this.className=this.className.replace(/ over/, '');});
  }
 }
}

function loadSBM(target, uid, title, link, count, deja){
 var tar = o(target), p = target.parentNode, pop, Y;
 if(p.lastChild.nodeType == 1 && p.lastChild.className == 'sbm-pop'){
  return;
 }
 if(deja){
  p.appendChild(oParts.fragment(loadSBM.tmp.replace(/%uid%/, uid).replace(/%title%/g, title).replace(/%link%/g, oParts.baseURL + link)));
  p.lastChild.className = "sbm-pop"; pop = o(p.lastChild);
  Y = oParts.metrics(1) - tar.offset(1) + oParts.metrics(3) > pop.rect(1) ? 16 : -pop.rect(1);
  pop.css("position: absolute; left:"+(100 - pop.rect(0))+"px; top:"+Y+"px");
  tar.on("click", function(){pop.show();});
  return;
 }
 oParts.server.get(baseURL + "ajax.php?type=sharedlink&UID="+uid+"&title="+title+"&link="+link, function(data){
  p.appendChild(oParts.fragment(data));
  p.lastChild.className = "sbm-pop"; pop = o(p.lastChild);
  Y = oParts.metrics(1) - tar.offset(1) + oParts.metrics(3) > pop.rect(1) ? 16 : -pop.rect(1);
  pop.css("position: absolute; left:"+(100 - pop.rect(0))+"px; top:"+Y+"px");
  tar.on("click", function(){pop.show();});
  if(count == 0 && !loadSBM.tmp){
   loadSBM.tmp = data.replace(/id="SBM\d+?"/, 'id="SBM%uid%"');
   loadSBM.tmp = loadSBM.tmp.replace(/(?:url|link|bkmk|u)=(http.+?)&amp;/g, function(a, b){return a.replace(b, '%link%');});
   loadSBM.tmp = loadSBM.tmp.replace(/(?:title|t)=([^"]+?)"/g, function(a, b){return a.replace(b, '%title%');});
  }
 });
}

oParts.start(function(){
 var state, ucss = o('#ppBlogCSS');
 ImagePath = ucss ? ucss.$.href.replace(/(^ht.+?\/theme\/[^/]+?\/).+$/, '$1') + 'Images/' : ImagePath;
 oParts.imgloader({
  'loadingAni' : 'loading.gif',
  'loaderAni' : 'loader.gif',
  'expandImg' : 'expand.png',
  'unexpandImg' : 'unexpand.png',
  'screenBack' : 'screen.png',
  'closeButton' : 'button-close.png'
 }, ImagePath);
 
 if(client.IE6) initCSSHover();

 if(typeof photoEffect != UD) photoEffect.init();
 o(d).on('click', function(){

  var cmt, non, p, s, pid, hash, tar = oParts.target();
  try {
   if(tar.klass('expand-icon')){
    p = tar.parent(2), pid = p.id, s = p.child(1);
    if(p && s) toggleBox(tar, s);
   }
   if(tar.$.nodeName == 'A' && /#weblog$/.test(tar.$.href)){
    tar.cancelEvent();
    o('#weblog').view(1);
   }
   if(tar.$.hash && /#(comments?|trackback|response)/.test(tar.$.hash)){
    hash = tar.$.hash;
    while (tar.parent()){
     if(tar.id && /^UID([0-9]+$)/.test(tar.id)){pid = tar.id.slice(3); break;}
     tar = tar.parent();
    }
    if(pid) oParts.evt.preventDefault();
    switch (hash){
     case '#responses' : case '#comments' : loadComments(pid); break;
     case '#comment' : loadCommentForm(pid, true); break;
     case '#trackback' : loadTrackBacks(pid, true); break;
    }
   }

   if(tar.$.nodeName == 'A'){
    if((' ' + tar.$.rel + ' ').indexOf('external') > 0){
     tar.$.target = '_blank';
    }
    if(tar.klass('intralink')){
     tar.cancelEvent();
     o(tar.$.href.split('/').pop()).view(1);
    }
    if(tar.$.href.indexOf('twitter') > 0){
     while (tar.parent()){
      if(tar.id && /^SBM([0-9]+$)/.test(tar.id)){var tid = tar.id.slice(3); break;}
      tar = tar.parent();
     }
     oParts.server.get(baseURL + "ajax.php?type=sbm_add&UID="+tid+"&sbm=twitter", function(data){ return data;});
    }
   }
   if(tar.id == 'login-entree'){tar.cancelEvent(); AjaxLogInForm();}

   if(tar.klass('sbm-entry')){
    var uid = /SBM:(\d+?)\t(\d+?)\t([^\t]+?)\t([^\t]+$)/.exec(tar.$.alt), pop = tar.$.parentNode.lastChild;
    var count = uid && Number(uid[1]);
    if(count == 0 && typeof loadSBM.tmp != UD){
     loadSBM(tar.$, uid[2], encodeURIComponent(uid[3]), uid[4], count, true);
    } else {
     if(uid) loadSBM(tar.$, uid[2], encodeURIComponent(uid[3]), uid[4], count, false);
     if(pop.className && pop.className != 'sbm-pop'){
      ajaxTooltip('情報を');
     }
    }
   }

   return false;
  } catch (e){ return false;}
 }); //#onclick
 
 cornerPlay(d);
 
 o(d).on('mousemove', function(){
  try {
   var tar = oParts.evt.target;
   if(tar.nodeName == 'A' && tar.rel){
    if((' ' + tar.rel + ' ').indexOf('external') > 0){
     if(tar.title == '') tar.title = '新しいウィンドウ(タブ)で開きます';
    }
   }
  } catch(e){;};
 });
 
 o(d).on('mouseover', function(){
  try {
   var evt = oParts.evt, tar;
   if(client.MSIE) evt.relatedTarget = evt.fromElement;
   if(evt && evt.relatedTarget){
    tar = evt.target;
    while (tar.parentNode){
     if(tar.className == 'sbm-pop') break;
     tar = tar.parentNode;
    }
    if(/sbm-pop|sbm-intro/.test(evt.relatedTarget.className) && tar.className != 'sbm-pop'){
     o(evt.relatedTarget).fade();
    }
   }
  } catch(e){;}
 });
 var sidebars = o('.sidebar-body', d.body);
 if(sidebars) sidebars.each(function(el){
  var c, ul, $id = el.parentNode.id;
  c = oParts.cookie.get('PPBLOG_SIDEBAR_'+$id.toUpperCase()+'_STATE') || '-';
  $id = o('#' + $id);
  if($id){
   ul = $id.child(1);
   if(ul){
    c == '+' ? ul.hide() : ul.show();
   } else return;
   var uv = ul.visible(), t = $id.child(0).child(0);
   t.css('background-position:' + ['0 100%', '0 0'][uv]).title(['展開！', '閉じます'][uv]);
  }
 });
 if(typeof pettieSyntax != UD) pettieSyntax();
 if(client.Gecko) oParts.loadScript(baseURL + 'js/firefoxtooltip.js');
});


window.alert = function(s){
 if(!confirm(s)) this.alert = function(){ return false};
}
